<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a number formatter</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.numberformatter.html">« NumberFormatter</a></li>
      <li style="float: right;"><a href="numberformatter.formatcurrency.html">NumberFormatter::formatCurrency »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.numberformatter.html">NumberFormatter</a></li>
    <li>Create a number formatter</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="numberformatter.create" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">NumberFormatter::create</h1>
  <h1 class="refname">numfmt_create</h1>
  <h1 class="refname">NumberFormatter::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">NumberFormatter::create</span> -- <span class="refname">numfmt_create</span> -- <span class="refname">NumberFormatter::__construct</span> &mdash; <span class="dc-title">Create a number formatter</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-numberformatter.create-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格 (method)
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>NumberFormatter::create</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$style</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$pattern</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.numberformatter.html" class="type NumberFormatter">NumberFormatter</a></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>numfmt_create</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$style</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$pattern</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.numberformatter.html" class="type NumberFormatter">NumberFormatter</a></span></span></div>

  <p class="para rdfs-comment">
   面向对象风格 (constructor):
  </p>
   <div class="constructorsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>NumberFormatter::__construct</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$style</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$pattern</code><span class="initializer"> = <strong><code>null</code></strong></span></span>)</div>

  <p class="para rdfs-comment">
   Creates a number formatter.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-numberformatter.create-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">locale</code></dt>

     <dd>

      <p class="para">
       Locale in which the number would be formatted (locale name, e.g. en_CA).
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">style</code></dt>

     <dd>

      <p class="para">
       Style of the formatting, one of the
       <a href="class.numberformatter.html#intl.numberformatter-constants.unumberformatstyle" class="link">
        format style</a> constants. If
       <strong><code>NumberFormatter::PATTERN_DECIMAL</code></strong>
       or <strong><code>NumberFormatter::PATTERN_RULEBASED</code></strong>
       is passed then the number format is opened using the given pattern,
       which must conform to the syntax described in
       <a href="http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details" class="link external">&raquo;&nbsp;ICU DecimalFormat
       documentation</a> or
       <a href="http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details" class="link external">&raquo;&nbsp;ICU RuleBasedNumberFormat
       documentation</a>, respectively.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">pattern</code></dt>

     <dd>

      <p class="para">
       Pattern string if the chosen style requires a pattern.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-numberformatter.create-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <span class="classname"><a href="class.numberformatter.html" class="classname">NumberFormatter</a></span> object or <strong><code>null</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-numberformatter.create-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">pattern</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-numberformatter.create-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2296">
   <p><strong>示例 #1 <span class="function"><strong>numfmt_create()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">numfmt_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">DECIMAL&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">numfmt_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'it'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">SPELLOUT&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1142</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2297">
   <p><strong>示例 #2 <span class="function"><strong>NumberFormatter::create()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">DECIMAL&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'it'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">SPELLOUT&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">1142</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
1.234.567,891
millicentoquarantadue
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-numberformatter.create-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="numberformatter.format.html" class="function" rel="rdfs-seeAlso">numfmt_format()</a> - Format a number</span></li>
    <li class="member"><span class="function"><a href="numberformatter.parse.html" class="function" rel="rdfs-seeAlso">numfmt_parse()</a> - Parse a number</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>